package io.renren.modules.lanling.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.lanling.entity.CertificateEntity;
import io.renren.modules.lanling.service.CertificateService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;

import static io.renren.modules.sys.shiro.ShiroUtils.getUserId;


/**
 * 证件表
 *
 * @author LANLING
 * @email lanling@gmail.com
 * @date 2018-11-26 15:50:09
 */
@RestController
@RequestMapping("lanling/certificate")
public class CertificateController {
    @Autowired
    private CertificateService certificateService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("lanling:certificate:list")
    public R list(@RequestParam Map<String, Object> params){
        Long userId = getUserId();
        params.put("createUserId", userId);
        PageUtils page = certificateService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("lanling:certificate:info")
    public R info(@PathVariable("id") Long id){
        CertificateEntity certificate = certificateService.selectById(id);

        return R.ok().put("certificate", certificate);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("lanling:certificate:save")
    public R save(@RequestBody CertificateEntity certificate){
        certificateService.insert(certificate);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("lanling:certificate:update")
    public R update(@RequestBody CertificateEntity certificate){
        ValidatorUtils.validateEntity(certificate);
        certificateService.updateAllColumnById(certificate);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("lanling:certificate:delete")
    public R delete(@RequestBody Long[] ids){
        certificateService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
